/*
 * @Author: your name
 * @Date: 2020-09-22 17:23:28
 * @LastEditTime: 2021-02-01 15:40:47
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \longh_admin\src\api\login.js
 */
import request from '@/utils/request'

const userApi = {
  Login: '/api/auth/login',
  Logout: '/api/logout',
  ForgePassword: '/api/auth/forge-password',
  Register: '/api/auth/register',
  twoStepCode: '/api/auth/2step-code',
  SendSms: '/api/account/sms',
  SendSmsErr: '/api/account/sms_err',
  // get my info
  // UserInfo: '/user/info',
  UserInfo:'/api/getLoginUserInfo',
  UserMenu: '/api/user/nav'
}

/**
 * login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param parameter
 * @returns {*}
 */
export function login (parameter) {
  return request({
    url: userApi.Login,
    method: 'post',
    data: parameter
  })
}

export function getSmsCaptcha (parameter) {
  return request({
    url: userApi.SendSms,
    method: 'post',
    data: parameter
  })
}

export function getInfo () {
  return request({
    url: userApi.UserInfo,
    method: 'post',
    // headers: {
    //   'Content-Type': 'application/json;charset=UTF-8'
    // }
  })
}

export function getCurrentUserNav () {
  return request({
    url: userApi.UserMenu,
    method: 'get'
  })
}

export function logout(){
  return request({
    url: userApi.Logout,
    method: 'get'
  })
}
// export function logout () {
//   return request({
//     url: userApi.Logout,
//     method: 'post',
//     headers: {
//       'Content-Type': 'application/json;charset=UTF-8'
//     }
//   })
// }

/**
 * get user 2step code open?
 * @param parameter {*}
 */
export function get2step (parameter) {
  return request({
    url: userApi.twoStepCode,
    method: 'post',
    data: parameter
  })
}


// 获取用户信息

export function GetUserInfo(data) {
  return request({
      url: '/api/auth/getLoginUserInfo',
      method: 'get',
      data
  })
}


// 退出登录

export function UserLogout(data) {
  return request({
      url: '/api/logout',
      method: 'GET',
      data
  })
}


// 获取用户token 
export function getAccessToken(code) {
  return request({
      url: '/api/auth/getAccessToken',
      method: 'get',
      // data: { code }
      headers: { code }
  })

}



